package com.googlecode.loframework.view.components.quizzes
{
	import com.googlecode.loframework.utils.CustomTextArea;
	
	import mx.containers.VBox;

	public class PersonalityQuestion extends VBox implements IPersonalityQuestion
	{
		private var _text:CustomTextArea;
		
		private var _title:String;
		
		private var _quizID:String;
		
		public function PersonalityQuestion()
		{
			super();
			
			percentWidth = 100;
			percentHeight = 100;
			setStyle("paddingBottom", 30);
			
			_text = new CustomTextArea();	
			_text.percentWidth = 100;
			_text.setStyle("backgroundAlpha", 0);
			_text.setStyle("borderStyle", "none");	
			_text.selectable = false;
			_text.editable = false;
			_text.styleName = "personalityQuestionText";
			

			
			addChild(_text);
		}
		
		// returns an array of all choices associated with this personality question
		public function get choices():Array
		{
			var list:Array = [];
			
			for(var i:uint=0; i<numChildren; i++)
			{
				if(getChildAt(i) is IChoice)
				{
					list.push(getChildAt(i) as IChoice);
				}
			}
			
			return list;
		}
		
		public function set title(value:String):void
		{
			_title = value;
			_text.text = value;
		}
		
		public function get title():String
		{
			return _title;
		}
		
		public function set quizID(id:String):void
		{
			_quizID = id;
		}
		
		public function get quizID():String
		{
			return _quizID;
		}
		
		// resets the textArea height if the text size has changed
		override protected function commitProperties():void
		{
			super.commitProperties();
			
			var lnHeight:int = 0;
			var numLines:int = _text.numLines;
			
			for(var i:uint=0; i<numLines; i++)
			{
				lnHeight += _text.getLineMetrics(i).height;
			}
			
			_text.height = lnHeight + 10;
		}
	}
}